import os.path
import time
import unittest
from HTMLTestRunner import HTMLTestRunner

base_dir = os.path.dirname(os.path.realpath(__file__))
dir_path = base_dir + "\\..\\result\\"


def test_add_subject():
    suite = unittest.TestLoader().discover('.', 'addSubject.py')
    name = "add_subject_test.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="添加专题UI测试报告", description="html测试")
        runner.run(suite)


def test_AduitBlog_Management():
    suite = unittest.TestLoader().discover('.', 'AduitBlogManagement.py')
    name = "AduitBlog_Management_test.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="根据标题查询已审核博文UI测试报告", description="html测试")
        runner.run(suite)


def test_NotAduitBlog_Management():
    suite = unittest.TestLoader().discover('.', 'NotAduitBlogManagement.py')
    name = "NotAduitBlog_Management_test.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="根据标题查询未审核博文UI测试报告", description="html测试")
        runner.run(suite)


def test_comment_Management():
    suite = unittest.TestLoader().discover('.', 'commentManagement.py')
    name = "comment_Management_test.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="根据用户名查找博文下评论UI测试报告", description="html测试")
        runner.run(suite)


def test_report_Management():
    suite = unittest.TestLoader().discover('.', 'reportManagement.py')
    name = "report_Management_test.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="根据举报原因查询举报信息UI测试报告", description="html测试")
        runner.run(suite)


def test_user_Management():
    suite = unittest.TestLoader().discover('.', 'userManagement.py')
    name = "user_Management.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="根据用户名查找用户信息UI测试报告", description="html测试")
        runner.run(suite)


def test_modify_blog():
    suite = unittest.TestLoader().discover('.', 'modifyBlog.py')
    name = "modify_blog.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="修改文章接口测试报告", description="html测试")
        runner.run(suite)


def test_add_blog():
    suite = unittest.TestLoader().discover('.', 'addBlog.py')
    name = "add_blog.html"
    report_path = dir_path + name
    with open(report_path, 'wb') as f:
        runner = HTMLTestRunner(stream=f, verbosity=2, title="添加文章接口测试报告", description="html测试")
        runner.run(suite)


if __name__ == "__main__":
    test_add_subject()
    test_AduitBlog_Management()
    test_NotAduitBlog_Management()
    test_comment_Management()
    test_report_Management()
    test_user_Management()
    test_modify_blog()
    test_add_blog()
